const app = getApp()

Page({
  data: {
    reasonType: "请选择原因",
    reportReasonArray: app.reportReasonArray,
    publishUserId: "",
    videoId: ""
  },
  //获取视频详情页面传过来的参数
  onLoad: function(params) {
    var me = this;
    var videoId = params.videoId;
    var publishUserId = params.publishUserId;


    //获取视频发布者ID和被举报视频的ID
    me.setData({
      publishUserId: publishUserId,
      videoId: videoId
    });
  },

  //选择举报理由
  changeMe: function(e) {
    var me = this;

    var index = e.detail.value;
    var reasonType = app.reportReasonArray[index];
    me.setData({
      reasonType: reasonType,
    });
  },
  //提交举报信息表单内容
  submitReport: function(e) {
    var me = this;
    var reasonIdex = e.detail.value.reasonIndex;
    var reasonContent = e.detail.value.reasonContent;

    //获取当前登陆者，也就是此时的举报者的id
    var user = app.getGlobalUserInfo();
    var currentUserId = user.id;

    if (reasonIdex == null || reasonIdex == '' || reasonIdex == undefined) {
      wx.showToast({
        title: '未选择举报理由',
        icon: "none"
      })
      return;
    }

    var serverUrl = app.serverUrl;

    wx.request({
      url: serverUrl + '/user/reportUser',
      method: 'POST',
      data: {
        dealUserId: me.data.publishUserId,
        dealVideoId: me.data.videoId,
        title: app.reportReasonArray[reasonIdex],
        content: reasonContent,
        userid: currentUserId
      },
      header: {
        'content-type': 'application/json', // 默认值
        'userId': user.id,
        'userToken': user.userToken,
      },
      success: function(res){
        wx.showToast({
           
          title: '举报成功...',
          icon: 'none',
          duration: 2000,
         
          // success: function(){
          //   setTimeout(function () {
          //     //要延时执行的代码
          //     wx.navigateBack();
          //   })
          // }, 2000)
          
          // },
          success: function () {
            
            setTimeout(function () {
              wx.navigateBack();
            }, 2000) //延迟时间
          }
        })
      }
    })

  }
})